#pragma once
#include <QtWidgets/QWidget>

#define BONDDETAILCHART_COUNT 4

class DetailData;
namespace qb
{
	class BondRateChart;
	class BondInterestRateChart;
	class BondQuoteDealChart;
	class BondQuoteBrokerChart;
	class BondQuoteCDCChart;
}

class BondDetailDealChartTitle;
class BondDetailQuoteChartTitle;
class BondDetailRateChartTitle;
class BondDetailCDCChartTitle;

using namespace qb;
class QVBoxLayout;

class BondDetailChart : public QWidget
{
public:
    BondDetailChart(QWidget* parent);
	~BondDetailChart();
    void setDetailData(QSharedPointer<DetailData> data);

protected:
	void setupUi();
	void initBondQuoteBorker();
	void initBondQuoteDeal();
	void initBondRate();
	void initBondInterestRate();
	void initBondQuoteCDC();

	void refreshMarketDealChart();
	void refreshBondDealKLineData();
	void refreshYeildAndIntChart();
	void refreshYeildChart();
	void refreshIntChart();

protected slots:
	// data
	void onBondChanged();
	void onDealChartKLineChanged(int type);
	void onDealChartMarketDealChanged();
	void onDealChartPreCloseChanged();
	void onBondRateChanged();
	void onBondInterestChanged();
	void onBondCDCChanged();
	void onMarketStreamDataChanged(QList<int> ids);

	// ui control
	void onBondDealTabSelRealTime();
	void onBondDealTabSelKLineAver();
	void onBondDealTabSelKLineClose();
	void onBondDealTabSelDate(int index);
	void onBondDealCalendarUpdate(int startDay, int endDay);
	void onQuoteYieldSelected();
	void onQuoteNetPriceSelected();
	void onQuoteAbValueSelected(int check);
	void onBondCreditSpreadSelected(int select);
	void onBondYieldSelected(int select);
	void onBondCDCYieldSelected(int check0, int check1);//估值，成交
	void onBondCDCNetPriceSelected(int check0, int check1);
	void onBondCDCDateTabSelected(int select);
	void onBondCDCCalendarUpdate(int startDay, int endDay);

	void onBondDealLeftDrag(double ratio);
	void onBondDealRightDrag(double ratio);
	void onBondDealCentralDrag(double ratio1, double ratio2);
	void onBondQuoteLeftDrag(double ratio);
	void onBondQuoteRightDrag(double ratio);
	void onBondQuoteCentralDrag(double ratio1, double ratio2);
	void onBondRateLeftDrag(double ratio);
	void onBondRateRightDrag(double ratio);
	void onBondRateCentralDrag(double ratio1, double ratio2);
	void onBondInterestLeftDrag(double ratio);
	void onBondInterestRightDrag(double ratio);
	void onBondInterestCentralDrag(double ratio1, double ratio2);
	void onChartDblClicked(QWidget* e);
public slots:
	void onBondCDCLeftDrag(double ratio);
	void onBondCDCRightDrag(double ratio);
	void onBondCDCCentralDrag(double ratio1, double ratio2);

private:
	BondRateChart*				mBondRateChart = nullptr;
	BondInterestRateChart*		mBondInterestRateChart = nullptr;
	BondQuoteDealChart*			mBondQuoteDealChart = nullptr;
	BondQuoteBrokerChart*		mBondQuoteBrokerChart = nullptr;
	BondQuoteCDCChart*			mBondQuoteCDCChart = nullptr;

	BondDetailDealChartTitle*	mBondDetailDealTitle = nullptr;
	BondDetailQuoteChartTitle*	mBondDetailQuoteTitle = nullptr;
	BondDetailRateChartTitle*	mBondDetailRateTitle = nullptr;
	BondDetailCDCChartTitle*	mBondDetailCDCTitle = nullptr;
	QVBoxLayout*				mDetailLayout[BONDDETAILCHART_COUNT];

	int						m_iTabDayLineType = 0;
    QSharedPointer<DetailData> m_data = nullptr;
	bool					m_chartExpand = false;
};
